{% extends "base.html" %}

{% block title %}我的签到{% endblock %}

{% block head %}
{{ super() }}
<link href="{{ static_url('my.css') }}" rel="stylesheet" type="text/css">
{% endblock %}

{% block body %}
{{ utils.header(current_user) }}

<section class="tpl">
  <div id="error-msg"> {% if msg or msg != '' %}<pre>{{msg}}</pre>{% endif %}</div>
  <div class="container">
    <h2>
      已注册仓库
      {% if adminflg %}
      <span type="span" class="btn btn-default"> 
        <a data-load-method="GET" class="modal_load"  href="/subscribe/signup_repos/{{userid}}/" title="注册模板仓库">注册</a>       
      </span>
      {% endif %}
    </h2>
    <table class="table table-hover">
      <thead>
        <tr>
          {% if adminflg %}
          <th style="text-align:center" title="仓库操作区">操作</th>
          {% endif %}
          <th style="text-align:center" title="注册的仓库名">仓库名</th>
          <th style="text-align:center" title="注册的仓库连接">链接</th>
          <th style="text-align:center" title="注册的仓库分支">分支</th>
          <th style="text-align:center" title="是否对仓库使用加速，仅对github有效">加速</th>
        </tr>
      </thead>
      <tbody>
        {% for repo in repos %}
        <tr>
          {% if adminflg %}
          <td style="text-align:center">
            {% if repo.reponame != 'default'%}
            <div class="btn-group btn-group-xs" role="group" aria-label="...">
                <button  type="button" class="btn btn-default btn-sm" name="unsubscribe_{{repo.reponame}}" title="取消注册此仓库" onclick="unsubscribe_repo('{{repo.reponame}}')">退订</input>
            </div>
            {% endif %}
          </td>
          {% endif %}
          <td style="text-align:center">{{ repo.reponame }}</td>
          <td style="text-align:center">
            <a href="{{ repo.repourl }}" target="_blank">{{ repo.repourl }}</a>
          </td>
          <td style="text-align:center">{{ repo.repobranch }}</td>
          <td style="text-align:center">{% if repo.repoacc %} 开启 {% else %} 关闭 {% endif %}</td>
        </tr>
        {% endfor %}
      </tbody>
    </table>
    <h2>
      模板
      {% if adminflg %}
      <span type="span" class="btn btn-default">
        <a data-method="POST" href="/subscribe/refresh/{{userid}}/?op=refresh" title="只更新,不清楚缓存">强制更新</a>
      </span>
      <span type="span" class="btn btn-default">
        <a data-method="POST" href="/subscribe/refresh/{{userid}}/?op=clear" title="有任务重复的时候，请尝试重建缓存">清缓存</a>
      </span>
      {% endif %}
      <span type="span" class="btn btn-default">
        <a href="https://github.com/qiandao-today/templates/issues/48" title="求模板链接" target="_blank">求模板</a>
      </span>
    </h2>
    <table class="table table-hover">
      <thead>
        <tr>
          <th style="text-align:center" title="模板操作区">操作</th>
          <th style="text-align:center" title="所属仓库">仓库</th>
          <th style="text-align:center" title="需签到的网站">网站</th>
          <th style="text-align:center" title="模板作者">作者</th>
          <th style="text-align:center" title="修改日期">修改日期</th>
          <th style="text-align:center" title="备注和修改日志">备注/日志</th>
        </tr>
      </thead>
      <tbody>
        {% for tpl in tpls | sort(attribute='date', reverse=True)%}
        <tr>
          <td style="text-align:center">
            <div class="btn-group btn-group-xs" role="group" aria-label="...">
                  <span type="span" class="btn btn-default">
                    <a href="/har/edit?reponame={{ tpl.reponame | urlencode }}&name={{ tpl.filename | urlencode }}" target="_blank" id="{{ tpl.name }}" title="订阅此模板">订阅</a>
                  </span>
            </div>
            {% if tpl.commenturl != '' %}
            <div class="btn-group btn-group-xs" role="group" aria-label="...">
              <span type="span" class="btn btn-default">
                <a href="{{tpl.commenturl}}" target="_blank" id="{{ tpl.name }}" title="跳转到评论区">评论</a>
              </span>
            </div>
            {% endif %}
          </td>
          <td style="text-align:center">{{ tpl.reponame }}</td>
          <td style="text-align:center">{{ tpl.name }}</td>
          <td style="text-align:center">{{ tpl.author | safe }}</td>
          <td style="text-align:center">{{ tpl.date | safe }}</td>
          <td style="text-align:center">{{ tpl.comments | safe }}</td>
        </tr>
        {% endfor %}
      </tbody>
    </table>
  </div>
</section>

{% if adminflg %}
<script>
  $(function() {
    $('[data-toggle=popover]').popover({
      trigger: 'hover'
    });
  })
</script>
<script>
 function unsubscribe_repo(name) {
   data = {
    reponame: name
   }
   $.ajax("/subscribe/unsubscribe_repos/{{userid}}/", {
          type: 'POST',
          data: data,
        })
        .done(function(data) {
         $('#error-msg').html(data).show()
        
        })
        .fail(function(jxhr) {
          $('#error-msg').html('<h1 class="alert alert-danger text-center">设置失败</h1><div class="well"></div>').show().find('div').text(jxhr.responseText);
        })
        .always(function() {
          $this.button('reset');
        });

        return false;
 }
</script>
{% endif %}

{{ utils.modal_load() }}
{{ utils.apost() }}
{% endblock %}